<!--
* @description 留言版
* @fileName message.vue
* @author huangyu
* @date 2022/06/23 22:24:07
!-->
<template>
    <div style="padding: 20px;">
        <el-form label-width="100px">
            <el-form-item label="留言内容：">
                <el-input v-model="msg" type="textarea" placeholder="请输入内容"></el-input>
            </el-form-item>
            <el-form-item label="">
                <el-button type="primary" @click="addMsg">提交留言</el-button>
            </el-form-item>
        </el-form>
        <el-table :data="msgList" border :max-height="menuHeight" size="mini">
            <el-table-column label="留言内容" prop="content" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column label="留言时间" prop="createTime" width="160">
                <template slot-scope="scope">
                    {{scope.row.createTime | formatDate}}
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
import { get } from '@/common/app.js'
import { formatDate } from '@/common/unit.js'
export default {
    components: {},
    data() {
        return {
            msg: "",
            msgList: [],
            menuHeight: document.documentElement.clientHeight - 140,
        }
    },
    mounted() {
        this.getMsg()
    },
    methods: {
        addMsg(){
            if(this.msg){
                let params = {
                    type: 'getAionMsg',
                    data: {
                        type: 'addMsg',
                        content: this.msg,
                        status: 1,
                    },
                }
                get('game',params).then(res=>{
                    if(res){
                        if(res.id){
                            this.$message.success("留言成功！")
                            this.getMsg()
                        }
                    }
                })
            }else{
                this.$message.error("请填写内容！")
            }
        },
        getMsg(){
            let params = {
                type: 'getAionMsg',
                data: {
                    type: 'getMsg',
                },
            }
            get('game',params).then(res=>{
                if(res){
                    this.msgList = res.data.reverse()
                }
            })
        },
    },
    filters: {
        formatDate(time) {
            var date = new Date(time);
            let res = formatDate(date, "yyyy-MM-dd hh:mm:ss");
            return res;
        },
    }
}
</script>

<style scoped>
</style>